package cn.tannn.cat.file.server.init;

import cn.tannn.cat.file.sdk.core.minio.MinioUtils;
import cn.tannn.cat.file.server.entity.FileStorageConfig;
import cn.tannn.cat.file.server.service.FileStorageConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * minio 项目启动加载所有客户端
 *
 * @author lxw
 * @version V1.0
 * @date 2021/2/1
 **/

@Slf4j
@Component
public class MinioInit implements ApplicationRunner {

	/**
	 * 存储配置
	 */
	@Autowired
	private FileStorageConfigService fileStorageConfigService;


	@Override
	public void run(ApplicationArguments args) {
		List<FileStorageConfig> minioConfig = fileStorageConfigService.findMinioConfig();
		minioConfig.forEach(client -> MinioUtils.createMinioClient(client.toFileStorage()));
	}
}
